#include "ExitChatNotify.h"

json ExitChatNotify::serialize() const {
    try{
        json j;
        j["type"]=type;
        j["sender_id"]=sender_id;
        j["receiver_id"]=receiver_id;
        j["chat_room_id"]=chat_room_id;
        j["content"]=content;
        j["time"]=time;
        return j;
    }catch(exception& e){
        syslog(LOG_ERR, "ExitChatNotify serialize error:%s", e.what());
        #ifdef DEBUG
        PRINT_ERRNO_AND_STRERROR(errno, "ExitChatNotify serialize error:%s", e.what());
        #endif
        throw e;
    }
}    

void ExitChatNotify::unserialize(const json& j) {
    try{
        this->type=j["type"].get<NotifyType>();
        this->sender_id=j["sender_id"].get<int>();
        this->receiver_id=j["receiver_id"].get<int>();
        this->chat_room_id=j["chat_room_id"].get<string>();
        this->content=j["content"].get<string>();
        this->time=j["time"].get<string>();
    }catch(exception& e){
        syslog(LOG_ERR, "ExitChatNotify unserialize error:%s", e.what());
        #ifdef DEBUG
        PRINT_ERRNO_AND_STRERROR(errno, "ExitChatNotify unserialize error:%s", e.what());
        #endif
        throw e;
    }
}

NotifyType ExitChatNotify::get_notify_type() const {
    return EXIT_CHAT_NOTIFY;
}

ExitChatNotify::ExitChatNotify(const int& sender_id, const int& receiver_id, const string& chat_room_id, const string& content, const string& time)
    {
    this->sender_id = sender_id;
    this->receiver_id=receiver_id;
    this->type = INVITE_RESULT_NOTIFY;
    this->chat_room_id = chat_room_id;
    this->content = content;
    this->time = time;
}

ExitChatNotify::ExitChatNotify(json exit_chat_notify_json) {
    unserialize(exit_chat_notify_json);
}   